﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace OA.DAL
{
    public class Button : Base<Model.Button>
    {
        public Button(ISession isession)
            : base(isession)
        {

        }

        public IList<Model.Button> GetByParent(string webSiteCode, string menuCode)
        {
            return Get("WebSiteCode=? and MenuCode=?", null, webSiteCode, menuCode);
        }

        public override Model.Button GetModel(object id)
        {
            Model.Button model = null;
            var list = Get("ID=?", null, id);
            if (list.Count > 0)
            {
                model = list[0];
            }
            return model;
        }

        public Common.Result Delete(string webSiteCode,string MenuCode,string ButtonCode)
        {
            var ret = DeleteByWhere("WebSiteCode=? and MenuCode=? and Code=?"
                , new object[] { webSiteCode, MenuCode, ButtonCode }
                , new NHibernate.Type.IType[] { NHibernateUtil.String, NHibernateUtil.String, NHibernateUtil.String });
            return ret;
        }

        public Model.Button GetModel(string WebSiteCode, string MenuCode, string ButtonCode)
        {
            Model.Button model = null;
            var list=Get("WebSiteCode=? and MenuCode=? and Code=?", null, WebSiteCode, MenuCode, ButtonCode);
            if (list.Count > 0)
            {
                model = list[0];
            }
            return model;
        }
    }
}
